<script type="text/javascript">
	<?php // oi 2 function pou stelnoun me ajax ti epelekse o xristis apo to aristero menu, se kathe click ?>
	function categoryfilter(x){

		var location = document.getElementsByName("location");
		var lo = location.length;

		var q;
		var d;

		d = $("#day1").datepicker({ dateFormat: "dd/mm/yy" }).val();

		if(d=="") {
			d=0;
		}

		for(i=0;i<lo;i++) {
				if(location[i].checked) {
					q=location[i].value;
					break;
				}else {
					q=0;
				}
		}	

		if (window.XMLHttpRequest)  {

			  xmlhttp=new XMLHttpRequest();

		}else  {

			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function()  {
			  
			if (xmlhttp.readyState==4 && xmlhttp.status==200)	{
				
				document.getElementById("mainadvsresults").innerHTML=xmlhttp.responseText;
			}
		}

		xmlhttp.open("GET","includes/ajax_livecategorysearch.php?category="+x+"&location="+q+"&date="+d,true);
		xmlhttp.send();	
	}


	function locationfilter(y){

		var category = document.getElementsByName("category");
		var lo = category.length;

		var q;
		var d;

		d = $("#day1").datepicker({ dateFormat: "dd/mm/yy" }).val();

		if(d=="") {
			d=0;
		}

		for(i=0;i<lo;i++) {
				if(category[i].checked) {
					q=category[i].value;
					break;
				}else {
					q=0;
				}
		}	
		
		if (window.XMLHttpRequest)  {

			  xmlhttp=new XMLHttpRequest();

		}else  {

			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function()  {
			  
			if (xmlhttp.readyState==4 && xmlhttp.status==200)	{
				
				document.getElementById("mainadvsresults").innerHTML=xmlhttp.responseText;
			}
		}

		xmlhttp.open("GET","includes/ajax_livecategorysearch.php?category="+q+"&location="+y+"&date="+d,true);
		xmlhttp.send();	
	}

  	$(function() { 
    	$("#day1").datepicker({ 
            dateFormat: 'dd-mm-yy',
            buttonImage: 'images/calendar.png', 
        });

    });

</script>

<label style="font-size:18px;color:#0000FF;">Φιλτράρισμα</label><br>

	<div><i>Κατηγορίες</i></div>
	<div style="text-align:left;">
	
		<?php
		$result = $setup->qry("Select * from CATEGORIES");

		while($row = mysql_fetch_assoc($result)) { ?>

			<input id="category<?php echo $row['cat_id']; ?>" name="category" value="<?php echo $row['cat_id']; ?>" type="radio"
			<?php if($row['cat_id']==$cat) { ?> checked="checked"  <?php } ?> onclick="categoryfilter(this.value);" /><?php echo $row['cat_desc']; ?><br>

		<?php }	?>

	</div>
	<br>
	<div><i>Τοποθεσία</i></div>
	<div style="text-align:left;">	
		<?php
		$result = $setup->qry("Select * from LOCATION");
		while($row = mysql_fetch_assoc($result)) { ?>

			<input id="location<?php echo $row['loc_id']; ?>" name="location" value="<?php echo $row['loc_id']; ?>" type="radio"
			<?php if($row['loc_id']==$loc) { ?> checked="checked" <?php } ?> onclick="locationfilter(this.value);" /><?php echo $row['loc_administrative_area_level_1']." ".$row['loc_locality']; ?><br>

		<?php }	?>
	
	</div>
	<br>
	<div><i>Ημερομηνία</i></div>
	<div>
		<form>
			<input id="day1" type="text" value="" readonly>	
		</form>
	</div>